package com.bitcoin.scheduler.dns;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.alidns.model.v20150109.*;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpResponse;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.http.ProtocolType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.apache.http.conn.util.DomainType;

import java.util.List;

public class DemoListDomains {
    private static IAcsClient client = null;

    static {
        String regionId = "cn-hangzhou"; //必填固定值，必须为“cn-hanghou”
        String accessKeyId = "LTAIHNlnvR9eHkuU"; // your accessKey
        String accessKeySecret = "4eefCyiEq4eWrIYkvUGzSAdPgpKYw2";// your accessSecret
        IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
        // 若报Can not find endpoint to access异常，请添加以下此行代码
        // DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Alidns", "alidns.aliyuncs.com");
        client = new DefaultAcsClient(profile);
    }

//    public static void main(String[] args) {
//        DescribeDomainRecordsRequest request = new DescribeDomainRecordsRequest();
//        request.setDomainName("hr8x.xyz");
//        request.setRRKeyWord("mail");
//        request.setProtocol(ProtocolType.HTTPS); //指定访问协议
//        request.setAcceptFormat(FormatType.JSON); //指定api返回格式
//        request.setMethod(MethodType.POST); //指定请求方法
//        request.setRegionId("cn-shanghai");//指定要访问的Region,仅对当前请求生效，不改变client的默认设置。
//        try {
//            DescribeDomainRecordsResponse  response = client.getAcsResponse(request);
//            List<DescribeDomainRecordsResponse.Record> list = response.getDomainRecords();
//            for (DescribeDomainRecordsResponse.Record record : list) {
//                System.out.println(record.getLine());
//            }
//        } catch (ClientException e) {
//            e.printStackTrace();
//        }
//    }

    public static void main(String[] args) {
        AddDomainRecordRequest request = new AddDomainRecordRequest();
        request.setDomainName("hr8x.xyz");
        request.setRR("lifei");
        request.setType("A"); //指定访问协议
        request.setValue("127.0.0.1"); //指定api返回格式
        request.setMethod(MethodType.POST); //指定请求方法
        request.setRegionId("cn-shanghai");//指定要访问的Region,仅对当前请求生效，不改变client的默认设置。
        request.setTTL(600L);
        try {
            AddDomainRecordResponse response = client.getAcsResponse(request);
            String list = response.getRecordId();
            System.out.println(list);
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}
